package com.sk.weichat.ui.me.redpacket;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;

import com.sk.weichat.bean.redpacket.RedpacketDetailBean;
import com.sk.weichat.ui.base.CoreManager;

/**
 * @author lzs
 * @date 2019/10/11
 * Email:343067508@qq.com
 **/
public class RedpacketRouter {
    /**
     * @param context
     * @param userID              用户id
     * @param redpacketDetailBean
     */
    public static final void route(@NonNull Context context, @NonNull String userID, String extra, @NonNull RedpacketDetailBean redpacketDetailBean) {
        //Log.e("lzs", "RedpacketRouter route");
        if (context == null || TextUtils.isEmpty(userID) || redpacketDetailBean == null) {
            return;
        }
        int status = redpacketDetailBean.getStatus();
        //发红包者id
        String fromId = String.valueOf(redpacketDetailBean.getUserId());
        //当前用户是否是发送者
        boolean isOwner = fromId.equals(userID);
        //是否群聊
        boolean isGroup = !TextUtils.isEmpty(redpacketDetailBean.getRoomId());
        //是否领取过
        boolean isOpened = redpacketDetailBean.getStatus() == RedpacketDetailBean.Status_opened;
        // 是否拼手气红包
        boolean isRandom = redpacketDetailBean.getType() == RedpacketDetailBean.type_random;

        if (status == RedpacketDetailBean.Status_expire) {
            //无法查看该记录
            RedPacketActivity2.startRedPacketActivity(context, redpacketDetailBean, extra);
            return;
        }
        if (!isGroup && !isOpened) {
            RedPacketActivity2.startRedPacketActivity(context, redpacketDetailBean, extra);
            return;
        }
        if (!isGroup && isOpened && !isOwner) {
            //领取者已领取
            PersonalRedPacketDetailsActivity.startPersonalRedPacketDetailsActivity(context, redpacketDetailBean);
            return;
        }
        if (isGroup && !isRandom && isOwner) {
            //普通红包发送者
            if (status == RedpacketDetailBean.Status_expire) {
                //无法查看该记录
                RedPacketActivity2.startRedPacketActivity(context, redpacketDetailBean, extra);
            } else {
                MucRedPacketDetailsActivity.startRedPacketDetailsActivity(context, redpacketDetailBean);
            }
            return;
        }
        if (isGroup && !isRandom && status == RedpacketDetailBean.Status_opened) {
            //群聊普通红包领取者已领取
            PersonalRedPacketDetailsActivity.startPersonalRedPacketDetailsActivity(context, redpacketDetailBean);
            return;
        }
        if (isGroup && isRandom && status == RedpacketDetailBean.Status_unopen) {
            //手气红包未领取
            RedPacketActivity2.startRedPacketActivity(context, redpacketDetailBean, extra);
            return;
        }
        if (isGroup && isRandom && status != RedpacketDetailBean.Status_unopen) {
            MucRedPacketDetailsActivity.startRedPacketDetailsActivity(context, redpacketDetailBean);
            return;
        }
        RedPacketActivity2.startRedPacketActivity(context, redpacketDetailBean, extra);
    }

}
